package com.gree.elasticsearch.service;

import com.frameworkset.orm.annotation.Transaction;
import com.gree.elasticsearch.dao.BoolRepository;
import com.gree.elasticsearch.domain.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * 总有刁民想害朕，请叫我小花狗
 * create by zxw on 2020/5/21
 */
@Service
public class BoolService {

    @Autowired
    private BoolRepository boolRepository;

    @Autowired
    private ToolService toolService;

    @Transactional(propagation = Propagation.REQUIRED)
    public Bool getBoolById(Integer id) {
        return Optional.ofNullable(boolRepository.findById(id).get()).orElse(new Bool());
    }

    @Transactional(propagation = Propagation.NESTED, rollbackFor = {Exception.class})
    public void createBool() {
        Bool bool = new Bool();
        bool.setBool(Thread.currentThread().getName());
        boolRepository.save(bool);
    }
}
